<?php
/**
 * 上周
*/

namespace houze\mongodb\query;

class lastweek {
    /**
     * 构造时间查询
    */
    public static function run($field, $where, $data) {
        $w = date('w');
        if ($w == 0) $w = 7;
        
        $ww = $w-1;//开始减的天数
        $rw =7-$w;//结束加的天数

        //上周
        $lww = $ww+7;//开始减的天数
        $lrw = $rw-7;//结束加的天数

        $start = strtotime(date('Y-m-d',strtotime("-{$lww} days")));
        $end = strtotime(date('Y-m-d',strtotime("+{$lrw} days")))+86399;
        
        return [
            [
                'field' => $field,
                'where' => '>=',
                'value' => $start,
            ],
            [
                'field' => $field,
                'where' => '<',
                'value' => $end,
            ],
        ];
    }
}